package com.personal_workspace_java.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import com.personal_workspace_java.common.R;
import com.personal_workspace_java.common.PageResponse;
import com.personal_workspace_java.service.TodoService;
import com.personal_workspace_java.model.dto.TodoDto;
import com.personal_workspace_java.model.vo.TodoVo;
/**
* @author 19324
*/
@Tag(name = "Todo相关接口")
@RestController
@RequestMapping("/Todo")
@Slf4j
public class TodoController{

    @Resource
    private TodoService todoService;

    //1.新增Todo
    @Operation(summary = "新增Todo")
    @PostMapping("/create")
    public R<Boolean> create(@RequestBody TodoDto todoDto){
        todoService.create(todoDto);
        return R.success("新增成功");
    }

    //2.查询ByTodoId
    @Operation(summary = "查询ByTodoId")
    @PostMapping("/queryByTodoId")
    public R<TodoVo> queryByTodoId(@RequestBody TodoDto todoDto){
        TodoVo todoVo=todoService.queryByTodoId(todoDto);
        return R.success(todoVo,"查询成功");
    }

    //3.查询By其他字段
    @Operation(summary = "查询By其他字段")
    @PostMapping("/queryByOther")
    public R<TodoVo> queryByOther(@RequestBody TodoDto todoDto){
        TodoVo todoVo=todoService.queryByOther(todoDto);
    return R.success(todoVo,"查询成功");
    }

    //4.查询所有
    @Operation(summary = "查询所有Todo")
    @PostMapping("/queryAll")
    public R<List<TodoVo>> queryAll(){
        List<TodoVo> todoVoList=todoService.queryAll();
        return R.success(todoVoList,"查询成功");
    }

    //5.删除ByTodoId
    @Operation(summary = "删除ByTodoId")
    @PostMapping("/deleteByTodoId")
    public R<Boolean> deleteByTodoId(@RequestBody TodoDto todoDto){
        todoService.deleteByTodoId(todoDto);
        return R.success("删除成功");
    }

    //6.修改ByTodoId
    @Operation(summary = "修改ByTodoId")
    @PostMapping("/updateByTodoId")
    public R<Boolean> updateByTodoId(@RequestBody TodoDto todoDto){
        todoService.updateByTodoId(todoDto);
        return R.success("修改成功");
    }

    //7.分页查询Todo
    @Operation(summary = "分页查询Todo")
    @PostMapping("/queryTodoByPage")
    public R<PageResponse<TodoVo>> queryTodoByPage(@RequestBody  TodoDto todoDto){
        PageResponse<TodoVo> pageResponse=todoService.queryTodoByPage(todoDto);
            return R.success(pageResponse,"查询成功");
        }

    }